//
//  KVOProxy.swift
//  Pods-ObserveTiming_Example
//
//  Created by JY_NEW on 2021/10/25.
//

import Foundation

@dynamicMemberLookup
public struct KVOProxy<OCType: NSObject> {
    let object: OCType
    weak var observer: AnyObject?
    public subscript<ValueType>(dynamicMember keyPath: KeyPath<OCType, ValueType>) -> KVOProxyValue<ValueType> {
        return KVOProxyValue<ValueType>()
    }
}
@dynamicCallable
public struct KVOProxyValue<ValueType> {
    public func before(_ action: @escaping (ValueType) -> Void) {
        
    }
    public func after(_ action: @escaping (_ old: ValueType, _ new: ValueType) -> Void) {
        
    }
    public func dynamicallyCall(withArguments actions: [(ValueType) -> Void]) {
        for action in actions {
            self.after { old, new in
                action(new)
            }
        }
    }
}
